<template>
  <Blank>
    <div class="works">
      <div class="con" v-if="worksList.length > 0">
        <div class="box" v-for="item in worksList" :key="item.id">
          <div class="poto" @click="gotoDetail(item.id)">
            <img :src="item.url" alt="" srcset="" />
          </div>
          <div class="des">
            <span @click="gotoDetail(item.id)">
              {{ item.name }}
            </span>
          </div>
        </div>
      </div>
      <div v-else class="not-con">暂无内容</div>
    </div>
  </Blank>
</template>

<script lang="ts" setup>
import { onMounted, ref } from "vue";
import Blank from "@/components/blankCard/BlankCard.vue";
import router from "@/router";
import { getWorksType } from "@/api/index";

const worksList = ref([]);

const initWorksInfo = async () => {
  const res = await getWorksType();
  if (res) {
    worksList.value = res;
  }
};

const gotoDetail = (id: number) => {
  router.push(`/worksDetail/${id}`);
};

onMounted(() => {
  initWorksInfo();
});
</script>

<style lang="scss" scoped>
.works {
  margin-top: 140px;
  .con {
    margin: 50px 0 20px;
    display: flex;
    flex-wrap: wrap;
    margin-left: -1%;
    .box {
      width: 150px;
      margin-left: 1%;
      margin-bottom: 30px;
      .poto {
        cursor: pointer;
        width: 150px;
        height: 150px;
        img {
          width: 100%;
          height: 100%;
          border-radius: 5px;
          transition: all 0.4s;
        }
        img:hover {
          transform: scale(1.05);
        }
      }
      .des {
        margin-top: 20px;
        span {
          font-size: 15px;
          color: #888;
          line-height: 25px;
        }
        span:hover {
          cursor: pointer;
          color: #0066ff;
          border-bottom: 1px solid #0066ff;
        }
      }
    }
  }
  .not-con {
    text-align: center;
    color: #888;
    font-size: 20px;
  }
}
</style>